<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Site/classes/PhpFox_ComponentStyleReplace.class.php, $Author:  $ */



/** Component for stylization user profile page
 * @version $Id: PhpFox_ComponentStyleReplace.class.php 455 2008-05-15 11:19:29Z phpfoxsv $
 * @package module.site
 *   
 */
class PhpFox_Mod_Site_ComponentStyleReplace extends BaseComponent
{
    function process()
    {
    	/*
        $oReq = &App::getRequest();

        $sUser = $oReq->get('name');
        if ( empty($sUser) )
        {
        	return '';
        }
        */	
		
		$oAcc = $this->getParam('oUser');
		$sUser = $oAcc->aData['user'];
		
		$aItem = $this->oDatabase->getRow('SELECT * FROM `'. App::getT('template') .'` AS t 
			WHERE t.user = "'. $oAcc->aData['user'] .'"');		
		
		if ( !isset($aItem['id']) )
		{
			return '';
		}

        $aStyles = array();
        $aStyleReplace = array();
        $sBgImage = '';
        if ($aItem['bg_img'])
        {
            $sUserBgPicUrl = App::getParam('user_bg.pic.url');
            if (!empty($aItem['bg_color']))
            {
            	$sBgImage = ' url("'.$sUserBgPicUrl.$sUser.'.jpg' . (App::getParam('force_re_cache') ? '?id=' . md5(rand(1003, 203948394)) : '') . '") fixed';
            }
            else 
            {
            	$aStyleReplace['body'] = 'background:url("'.$sUserBgPicUrl.$sUser.'.jpg' . (App::getParam('force_re_cache') ? '?id=' . md5(rand(1003, 203948394)) : '') . '") fixed;';
            }
        }
        $aStyles[]['body']              = array($aItem['bg_color'], 'background: <%>' . $sBgImage . ';');
        $aStyles[]['#main']             = array($aItem['bg_main'], 'background: <%>;');
        $aStyles[]['body']              = array($aItem['color_main'], 'color: <%>;');
        $aStyles[]['#main']             = array($aItem['color_main'], 'color: <%>;');
        $aStyles[]['a']                 = array($aItem['link_on'], 'color: <%>;');
        $aStyles[]['a:hover']           = array($aItem['link_hover'], 'color: <%>;');
        $aStyles[]['#top']              = array($aItem['username_bg'], 'background: <%>;');
        $aStyles[]['#top']              = array($aItem['username_color'], 'color: <%>;');
        $aStyles[]['#top a']            = array($aItem['username_color'], 'color: <%>;');
        $aStyles[]['#top a:hover']      = array($aItem['username_color'], 'color: <%>;');
        $aStyles[]['.top2']             = array($aItem['top_menu'], 'background: <%>;');
        $aStyles[]['.mainmenu5']        = array($aItem['mainmenu4'], 'background: <%>;');
        $aStyles[]['.mainmenu5']        = array($aItem['mainmenu4_txt'], 'color: <%>;');
        $aStyles[]['.border2']          = array($aItem['border2'], 'background: <%>;');
        $aStyles[]['.border2']          = array($aItem['border2_txt'], 'color: <%>;');
        $aStyles[]['.color']            = array($aItem['border2_txt'], 'color: <%>;');
        $aStyles[]['.border2']          = array($aItem['nav2_a2_bg'], 'border: 1px <%> solid;');
        $aStyles[]['.border13']         = array($aItem['nav2_a_bg'], 'background: <%>;');
        $aStyles[]['.border13']         = array($aItem['nav2_a_txt'], 'color: <%>;');
        $aStyles[]['.border13 a']       = array($aItem['nav2_a_txt'], 'color: <%>;');
        $aStyles[]['.border13 a:hover'] = array($aItem['nav2_a_txt'], 'color: <%>;');
        $aStyles[]['.comment']          = array($aItem['cmt_bg'], 'background: <%>;');
        $aStyles[]['.comment-text']     = array($aItem['cmt_txt'], 'color: <%>;');
        $aStyles[]['.comment-head']     = array($aItem['cmt2_bg'], 'background: <%>;');
        $aStyles[]['.comment-head']     = array($aItem['cmt2_txt'], 'color: <%>;');
        $aStyles[]['.comment-head a']     = array($aItem['cmt2_txt'], 'color: <%>;');
        $aStyles[]['.comment-head a:hover']     = array($aItem['cmt2_txt'], 'color: <%>;');
        $aStyles[]['#outer2']           = array($aItem['menu_a'], 'background: <%>;');
        $aStyles[]['.menu']             = array($aItem['menu_a'], 'background: <%>;');
        $aStyles[]['.menu']           = array($aItem['menu_a_txt'], 'color: <%>;');
        $aStyles[]['.menu a']           = array($aItem['menu_a_txt'], 'color: <%>;');
        $aStyles[]['.menu2']            = array($aItem['menu2_a'], 'background: <%>;');
        $aStyles[]['.menu2']          = array($aItem['menu2_a_txt'], 'color: <%>;');
        $aStyles[]['.menu2 a']          = array($aItem['menu2_a_txt'], 'color: <%>;');
        $aStyles[]['.menu2 a:hover']          = array($aItem['menu2_a_txt'], 'color: <%>;');
        $aStyles[]['.item3']            = array($aItem['nav1_bg'], 'border-bottom: 1px <%> solid;');
        $aStyles[]['.item3']            = array($aItem['nav2_sqr'], 'color: <%>;');
        $aStyles[]['.item2']            = array($aItem['nav1_bg'], 'border-bottom: 1px <%> solid;');
        $aStyles[]['.item2']            = array($aItem['nav1_bg'], 'border-top: 2px <%> solid;');
        $aStyles[]['.item2']            = array($aItem['nav1_bg'], 'border-left: 1px <%> solid;');
        $aStyles[]['.item2']            = array($aItem['nav1_bg'], 'border-right: 1px <%> solid;');
        $aStyles[]['.item']             = array($aItem['nav1_bg'], 'border-bottom: 1px <%> solid;');
        $aStyles[]['.item']             = array($aItem['nav1_bg'], 'border-top: 1px <%> solid;');
        $aStyles[]['.item']             = array($aItem['nav1_bg'], 'border-left: 1px <%> solid;');
        $aStyles[]['.item']             = array($aItem['nav1_bg'], 'border-right: 1px <%> solid;');
        $aStyles[]['.item']             = array($aItem['nav1_a_bg'], 'background: <%>;');
        $aStyles[]['.item a']           = array($aItem['nav1_a_txt'], 'color: <%>;');
        $aStyles[]['.item a:hover']     = array($aItem['nav1_a_txt'], 'color: <%>;');
        $aStyles[]['.item2']            = array($aItem['nav1_a2_bg'], 'background: <%>;');
        $aStyles[]['.item2 a']          = array($aItem['nav1_a2_txt'], 'color: <%>;');
        $aStyles[]['.item2 a:hover']    = array($aItem['nav1_a2_txt'], 'color: <%>;');
        $aStyles[]['#bottom3']          = array($aItem['bottom'], 'background: <%>;');
        $aStyles[]['#bottom4']          = array($aItem['bottom'], 'background: <%>;');
        $aStyles[]['#bottom4']          = array($aItem['bottom_txt'], 'color: <%>;');
        $aStyles[]['#bottom3']          = array($aItem['bottom_txt'], 'color: <%>;');
        $aStyles[]['#bottom3 a']        = array($aItem['bottom_txt'], 'color: <%>;');
        $aStyles[]['#bottom3 a:hover']  = array($aItem['bottom_txt'], 'color: <%>;');        
        
        foreach ($aStyles as $aStyle)
        {
            foreach ($aStyle as $sKey => $aRow)
            {
                list($sItem, $sTemplate) = $aRow;
                $aStyleReplace[$sKey] = $this->replaceStyleClass(isset($aStyleReplace[$sKey]) ? $aStyleReplace[$sKey] : '', $sItem, $sTemplate);
            }
        }
        foreach ($aStyleReplace as $iKey => $sReplace)
        {
            if (!$sReplace)
            {
                unset($aStyleReplace[$iKey]);
            }
        }
        
        $aItem['css'] = preg_replace('/-moz-binding/i', '', $aItem['css']);
        $this->oTpl->assignSrc('aStyleReplace', $aStyleReplace);
        $this->oTpl->assignSrc('sAdvancedStyle', $aItem['css']);
        return $this->oTpl->fetch('StyleReplace.html');
    }
    
    function replaceStyleClass($sProperties, $sColor, $sTemplate)
    {
        $sOut = '';
        if ($sColor)
        {
            $sOut = str_replace('<%>', $sColor, $sTemplate);
        }
        if ($sProperties)
        {
            $sOut = $sProperties.' '.$sOut;
        }
        return $sOut;
    }
}
?>